<%@ page import="com.wuming.caiwu.security.SecurityHander" %>
<%--
  Created by IntelliJ IDEA.
  User: zengyao
  Date: 2018/6/29
  Time: 17:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>操作员管理</title>
    <link rel="stylesheet" href="${allServerPath}static/layui/layui/css/layui.css">
    <style>
        .query-condition {
            margin-top: 15px;
        }
    </style>
</head>
<body style="background-color: #f0f2f5;">
<div style="padding: 15px;margin: 15px;background-color: #fff;">
    <button name="addOperator" class="layui-btn layui-btn-normal query-condition">添加操作员</button>

    <table id="userInfo" lay-filter="test" lay-data="{height: 'full-200'}"></table>
</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">编辑</a>
    <%--<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>--%>
    <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="statusq">
    {{#  if(d.status == '0'){ }}
    <span style="color: #FF0000;">无效</span>
    {{#  } else { }}
    <span>有效</span>
    {{#  } }}
</script>

<script type="text/html" id="roleTpl">
    {{#  if(d.role == '3'){ }}
    <span>前台</span>
    {{#  } else if(d.role == '4'){ }}
    <span>财务</span>
    {{#  } else if(d.role == '5'){ }}
    <span>教练</span>
    {{#  } else if(d.role == '6'){ }}
    <span>校长</span>
    {{#  } else if(d.role == '7'){ }}
    <span>报名点管理员</span>
    {{#  } }}
</script>


<script src="${allServerPath}static/layui/layui/layui.js"></script>
<script>
    layui.config({
        base: '${allServerPath}static/layui/build/js/'
    }).use(['table', 'jquery', 'navbar'], function () {
        var table = layui.table,
                $ = layui.jquery;

        table.render({
            elem: '#userInfo'
//            , height: 315
            , url: '${allServerPath}web/member/list.htmls?t=' + Date.parse(new Date()) //数据接口
            , page: true //开启分页
            , cols: [[ //表头
                {field: 'id', title: 'ID', width: 70, align: 'center', fixed: 'left'}
                , {field: 'userName', title: '用户名', align: 'center', width: 150}
                , {field: 'company', title: '单位名称', align: 'center', width: 180}
                , {field: 'phone', title: '联系人手机号', align: 'center', width: 140}
                , {field: 'createTime', title: '添加时间', align: 'center', width: 180}
                , {field: 'status', title: '用户状态', width: 100, align: 'center', templet: '#statusq'}
                , {fixed: 'right', title: '操作', align: 'center', toolbar: '#barDemo'}
            ]],
            id: 'userContent',
            method: 'post',
            page: true,
            where: {
                "memberId": "<%=SecurityHander.getCurrentUserId()%>"
            },
            request: {
                pageName: 'pageIndex', //页码的参数名称，默认：page
                limitName: 'pageSize'
            }, //如果无需自定义请求参数，可不加该参数
            response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , statusCode: 200 //成功的状态码，默认：0
                , msgName: 'message' //状态信息的字段名称，默认：msg
                , countName: 'total' //数据总数的字段名称，默认：count
                , dataName: 'data' //数据列表的字段名称，默认：data
            },
            done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                console.log(res);
                //得到当前页码
                console.log(curr);
                //得到数据总量
                console.log(count);
            },
            text: {
                none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            }

        });
        table.on('tool(test)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'detail') {
//                layer.msg('ID：' + data.id + ' 的查看操作')
                parent.window.tab.tabAdd({
                    'title': '查看用户信息',
                    'icon': '',
                    'url': '${allServerPath}web/member/editMember/' + data.id + '.htmls'
                });
            } else if (layEvent === 'del') {
                layer.confirm('真的删除么', function (index) {
                    $.ajax({
                        url: '${allServerPath}web/member/delete/' + data.id + ".htmls",
                        method: 'get',
                        dataType: 'json',
                        success: function (result) {
                            if (result.success) {
                                obj.del(); //删除对应行（tr）的DOM结构
                                layer.close(index);//向服务端发送删除指令
                            }
                        },
                        error: function () {
                            layer.msg('删除失败,请稍后重试.');
                        }
                    });
                });
            }
        });

        $("button[name='addOperator']").click(function () {
            layer.open({
                type: 2,
                title: '添加操作员',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['730px', '560px'],
                end: function () {
                    table.reload('userContent', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    });
                },
                content: ['${allServerPath}web/member/toEditOperator.htmls']
            });
        });
    });


</script>

</body>
</html>
